package com.woniu.gf.pawn.comm.core.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.http.MethodType;

/**
 * @BelongsProject: gf-pawn-system
 * @BelongsPackage: com.woniu.gf.pawn.comm.core.util
 * @Author: wu wei
 * @CreateTime: 2020-10-11 18:55
 * @Description: 短信发送工具类
 */
public class SendSmsUtil {
    public static Boolean sendCodeMessage(String phone,String code){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "LTAI4FzvMcsyCDikpj6WeddG",
                "4xYrU1JG1crg1QrOEFFHa5n4ao81GD");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        //手机号
        request.putQueryParameter("PhoneNumbers",phone);
        //模板信息
        request.putQueryParameter("SignName","ABC联盟商城");
        request.putQueryParameter("TemplateCode","SMS_204290877");
        request.putQueryParameter("TemplateParam","{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return response.getHttpResponse().isSuccess();
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }

}
